#include<bits/stdc++.h>
using namespace std;
struct IP{
	int i1,i2,i3,i4;
	int port;
	IP(){}
	IP(int j1,int j2,int j3,int j4,int jport){
		i1=j1,
		i2=j2,
		i3=j3,
		i4=j4,
		port=jport;
	}
	bool operator >(const IP a) const{
		if(i1!=a.i1)return i1>a.i1;
		if(i2!=a.i2)return i2>a.i2;
		if(i3!=a.i3)return i3>a.i3;
		if(i4!=a.i4)return i4>a.i4;
		return port>a.port;
	}
	bool operator <(const IP a) const{
		if(i1!=a.i1)return i1<a.i1;
		if(i2!=a.i2)return i2<a.i2;
		if(i3!=a.i3)return i3<a.i3;
		if(i4!=a.i4)return i4<a.i4;
		return port<a.port;
	}
};
map<IP,int> server;
int n;
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int r=0;r<n;r++){
		string type,ips;
		bool ok=1;
		cin>>type;
		if(type=="Server"){
			cin>>ips;
			int points[4];
			int pnum=0;
			for(int i=0;i<ips.size();i++){
				if(ips[i]=='.'){
					if(pnum==3||(ips[i+1]=='0'&&(!(ips[i+2]=='.'||ips[i+2]==':')))){
						ok=0;
						break;
					}
					points[pnum]=i;
					pnum++;
				}else if(ips[i]==':'){
					if(pnum!=3||(ips[i+1]=='0'&&i+2!=ips.size())){
						ok=0;
						break;
					}
					points[3]=i;
				}
				else if(ips[i]<'0'||ips[i]>'9'){
					ok=0;
					cerr<<3;
					break;
				}
			}
			if(!ok){
				cout<<"ERR"<<endl;
				continue;
			}
			int i1=0,i2=0,i3=0,i4=0;
			int port=0;
			for(int i=0;i<points[0];i++){
				i1*=10;
				i1+=ips[i]-'0';
			}
			for(int i=points[0]+1;i<points[1];i++){
				i2*=10;
				i2+=ips[i]-'0';
			}
			for(int i=points[1]+1;i<points[2];i++){
				i3*=10;
				i3+=ips[i]-'0';
			}
			for(int i=points[2]+1;i<points[3];i++){
				i4*=10;
				i4+=ips[i]-'0';
			}
			for(int i=points[3]+1;i<ips.size();i++){
				port*=10;
				port+=ips[i]-'0';
			}
			if(i1>=256||i2>=256||i3>=256||i4>=256||port>=65536){
				cout<<"ERR"<<endl;
				continue;
			}
			IP ip=IP(i1,i2,i3,i4,port);
			if(!server[ip]){
				server[ip]=r+1;
				cout<<"OK"<<endl;
			}
			else{
				cout<<"FAIL"<<endl;
			}
		}
		if(type=="Client"){
			cin>>ips;
			int points[4];
			int pnum=0;
			for(int i=0;i<ips.size();i++){
				if(ips[i]=='.'){
					if(pnum==3||(ips[i+1]=='0'&&(!(ips[i+2]=='.'||ips[i+2]==':')))){
						ok=0;
						break;
					}
					points[pnum]=i;
					pnum++;
				}else if(ips[i]==':'){
					if(pnum!=3||(ips[i+1]=='0'&&i+2!=ips.size())){
						ok=0;
						break;
					}
					points[3]=i;
				}
				else if(ips[i]<'0'||ips[i]>'9'){
					ok=0;
					cerr<<3;
					break;
				}
			}
			if(!ok){
				cout<<"ERR"<<endl;
				continue;
			}
			int i1=0,i2=0,i3=0,i4=0;
			int port=0;
			for(int i=0;i<points[0];i++){
				i1*=10;
				i1+=ips[i]-'0';
			}
			for(int i=points[0]+1;i<points[1];i++){
				i2*=10;
				i2+=ips[i]-'0';
			}
			for(int i=points[1]+1;i<points[2];i++){
				i3*=10;
				i3+=ips[i]-'0';
			}
			for(int i=points[2]+1;i<points[3];i++){
				i4*=10;
				i4+=ips[i]-'0';
			}
			for(int i=points[3]+1;i<ips.size();i++){
				port*=10;
				port+=ips[i]-'0';
			}
			if(i1>=256||i2>=256||i3>=256||i4>=256||port>=65536){
				cout<<"ERR"<<endl;
				continue;
			}
			IP ip=IP(i1,i2,i3,i4,port);
			//cout<<int(i1)<<"."<<int(i2)<<"."<<int(i3)<<"."<<int(i4)<<":"<<port<<endl;
			if(server[ip]){
				cout<<server[ip]<<endl;
			}
			else{
				cout<<"FAIL"<<endl;
			}
		}
	}
	return 0;
}
